package br.com.sistema.models;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.Version;

@Entity
@Table(name="estado")
public class Estado {

	@ManyToOne
	@JoinColumn(name="paisid", nullable=false)
	private Pais pais;
	
	@Id
	@Column(name="estaid")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer estaid;
	
	@Column(name="estanome", length=50, nullable=false)
	private String estanome;
	
	@Column(name="estacodnum", length=10, nullable=false)
	private String estacodnum;
	
	@Column(name="estaalf2", length=2)
	private String estaalf2;
	
	@Column(name="xdatai", nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar xdatai;
	
	@Column(name="xdatau", nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar xdatau;
	
	@Column(name="xusuario", nullable=false)
	private String xusuario;

	@Version
	@Column(name="xversao")
	private Integer xversao;

	@Transient
	private String paisnome;
	
	@PrePersist
	public void prePersist(){
		xdatai = Calendar.getInstance();
		xdatau = Calendar.getInstance();
	}
	
	@PreUpdate
	public void preUpdate(){
		xdatau = Calendar.getInstance();
	}
	
	public Pais getPais() {
		return pais;
	}

	public void setPais(Pais pais) {
		this.pais = pais;
	}

	public Integer getEstaid() {
		return estaid;
	}

	public void setEstaid(Integer estaid) {
		this.estaid = estaid;
	}

	public String getEstanome() {
		return estanome;
	}

	public void setEstanome(String estanome) {
		this.estanome = estanome;
	}

	public String getEstacodnum() {
		return estacodnum;
	}

	public void setEstacodnum(String estacodnum) {
		this.estacodnum = estacodnum;
	}

	public String getEstaalf2() {
		return estaalf2;
	}

	public void setEstaalf2(String estaalf2) {
		this.estaalf2 = estaalf2;
	}

	public Calendar getXdatai() {
		return xdatai;
	}

	public void setXdatai(Calendar xdatai) {
		this.xdatai = xdatai;
	}

	public Calendar getXdatau() {
		return xdatau;
	}

	public void setXdatau(Calendar xdatau) {
		this.xdatau = xdatau;
	}

	public String getXusuario() {
		return xusuario;
	}

	public void setXusuario(String xusuario) {
		this.xusuario = xusuario;
	}
	
	public String getPaisnome() {
		return this.pais.getPaisnome();
	}
}
